package com.szlanyou.thirdsdk.retrofit.file.upload;

import com.szlanyou.thirdsdk.retrofit.client.HttpClient;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

/**
 * @author 陈章
 * create at 2020/11/23 10:09
 * desc:创建文件上传的Observable
 */
public class FileUploadObservableGenerator {
    /**
     * 多个文件上传
     *
     * @param uploadUrl
     * @param params
     * @param uploadFileWrapperList
     * @return
     */
    public static Observable<ResponseBody> create(HttpClient httpClient, String uploadUrl, Map<String, Object> params, List<UploadFileWrapper> uploadFileWrapperList, String uniqueUploadFileRequestId, Map<String, Object> headerMap) {
        UploadFileService service = httpClient.getRetrofitClient().getService(UploadFileService.class);
//        return service.uploadFile(uploadUrl, MultipartGenerator.generate(params, uploadFileWrapperList), uniqueUploadFileRequestId, headerMap);
        return service.uploadFile(uploadUrl, MultipartGenerator.generate(params, uploadFileWrapperList), uniqueUploadFileRequestId);
    }

    /**
     * 单个文件上传
     *
     * @param uploadUrl
     * @param params
     * @param uploadFileWrapper
     * @return
     */
    public static Observable<ResponseBody> create(HttpClient httpClient, String uploadUrl, Map<String, Object> params, UploadFileWrapper uploadFileWrapper, String uniqueUploadFileRequestId, Map<String, Object> headerMap) {
        ArrayList<UploadFileWrapper> uploadFileWrapperList = new ArrayList<>();
        if (uploadFileWrapper != null) {
            uploadFileWrapperList.add(uploadFileWrapper);
        }
        return create(httpClient, uploadUrl, params, uploadFileWrapperList, uniqueUploadFileRequestId, headerMap);
    }

}
